package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.BoardStation;
import com.fbt.andon.domain.CallHelp;

import com.fbt.andon.domain.StopLine;
import com.fbt.andon.service.impl.CallHelpServiceImpl;
import com.linkwechat.common.core.controller.BaseController;

import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 呼叫帮助Controller
 *
 * @author fengtao
 * @date 2021-08-11
 */
@RestController
@RequestMapping("/call")
@Api(description = "呼叫信息")
public class CallHelpController extends BaseController {
    @Autowired
    private CallHelpServiceImpl callHelpService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/query")
    @ApiOperation("查询呼叫信息")
    public AjaxResult findCallList() {
        startPage();
        return AjaxResult.success("查询成功", callHelpService.list(null));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/list")
    @ApiOperation("根据产线模糊查询产线信息")
    public AjaxResult list(String lineName) {
        startPage();
        QueryWrapper<CallHelp> wrapper = new QueryWrapper<>();
        wrapper.like("line", lineName);
        return AjaxResult.success("查询成功", callHelpService.list(wrapper));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @ApiOperation("获取呼叫帮助详细信息，参数id")
    @GetMapping("/getCallById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer pkId) {
        return AjaxResult.success("获取成功", callHelpService.getById(pkId));
    }


    //@PreAuthorize(hasPermi = "mes:andon:add")
    @ApiOperation("增加，参数callHelp")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CallHelp callHelp) {
        return AjaxResult.success("新增成功", callHelpService.save(callHelp));
    }


    //@PreAuthorize(hasPermi = "mes:andon:edit")
    @ApiOperation("修改呼叫帮助，参数callHelp")
    @PostMapping("/updateById")
    public AjaxResult edit(@RequestBody CallHelp callHelp) {
        return AjaxResult.success("修改成功", callHelpService.updateById(callHelp));
    }


    //@PreAuthorize(hasPermi = "mes:andon:remove")
    @ApiOperation("批量删除岗位信息")
    @PostMapping("/batchRemove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success("删除成功", callHelpService.removeByIds(Arrays.asList(ids)));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @PostMapping("/findByTime")
    @ApiOperation("根据时间段来查询呼叫信息")
    public AjaxResult remove(String startTime, String endTime) {
        QueryWrapper<CallHelp> wrapper = new QueryWrapper<>();
        wrapper.between("stop_line", startTime, endTime); // 区间
        return AjaxResult.success("查询成功", callHelpService.list(wrapper));// 查询结果数
    }
}
